﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Athanor.Gui
{
    public class TextureGrid : ITextureGroup
    {
        Texture2D texture;
        int rows, cols;
        int numFrames;
        int frameWidth, frameHeight;

        public TextureGrid(Texture2D _texture, int _rows, int _cols, int _numFrames)
        {
            texture = _texture;
            rows = _rows;
            cols = _cols;
            numFrames = _numFrames;
            frameWidth = texture.Width / cols;
            frameHeight = texture.Height / rows;
        }

        int ITextureGroup.getNumFrames() { return numFrames; }
        Texture2D ITextureGroup.getTexture(int index) { return texture; }
        Rectangle ITextureGroup.getRect(int index) {
            int Left = (index % cols) * frameWidth;
            int Top = (index / cols) * frameHeight;
            return new Rectangle(Left, Top, frameWidth, frameHeight);
        }
    }
}
